package com.ruoyi.common.minio.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@FeignClient(name = "chunk-client", url = "${ai.address}")
public interface ChunkFeign {

    /**
     * 创建数据集
     * @param datasetId
     * @param documentId
     * @param authorization
     * @param requestBody
     * {
     *     "name":string
     *    "avatar":string
     *    "description":string
     *    "language":string
     *    "embedding_model":string
     *    "permission":string
     *    "chunk_method":string
     *    "parser_config":object
     * }
     * @return
     */
    @PostMapping(
            value = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> createChunk(
            @PathVariable("dataset_id") String datasetId,
            @PathVariable("document_id") String documentId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );

    /**
     * 列出块
     * @param datasetId
     * @param documentId
     * @param authorization
     * @param keywords
     * @param page
     * @param pageSize
     * @param chunkId
     * @return
     */
    @GetMapping(
            value = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> getChunks(
            @PathVariable("dataset_id") String datasetId,
            @PathVariable("document_id") String documentId,
            @RequestHeader("Authorization") String authorization,
            @RequestParam(value = "keywords", required = false) String keywords,
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "page_size", required = false) Integer pageSize,
            @RequestParam(value = "id", required = false) String chunkId
    );

    /**
     * 删除数据集
     * @param datasetId
     * @param documentId
     * @param authorization
     * @param requestBody
     * @return
     */
    @DeleteMapping(
            value = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> deleteChunks(
            @PathVariable("dataset_id") String datasetId,
            @PathVariable("document_id") String documentId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );

    /**
     * 更新数据集
     * @param datasetId
     * @param documentId
     * @param chunkId
     * @param authorization
     * @param requestBody
     * {
     *     "name":string
     *     "embedding_model":string
     *     "chunk_method":enum<string>
     * }
     * @return
     */
    @PutMapping(
            value = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> updateChunk(
            @PathVariable("dataset_id") String datasetId,
            @PathVariable("document_id") String documentId,
            @PathVariable("chunk_id") String chunkId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );

    /**
     * 检索数据块
     * @param authorization
     * @param requestBody
     * {
     *     "question":string
     *      "dataset_ids":list[string]
     *      "document_ids":list[string]
     *      "page":integer
     *      "page_size":integer
     *      "similarity_threshold":float
     *      "vector_similarity_weight":float
     *      "top_k":integer
     *      "rerank_id":string
     *     "keyword":boolean
     *     "highlight":boolean
     * }
     * @return
     */
    @PostMapping(
            value = "/api/v1/retrieval",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> retrieveData(
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );

}
